<template>
  <el-card class="AuthorCard-content" shadow="never">
    <div slot="header" class="header">
      <a @click="GoAuthorPage" class="author" :underline="false">{{
        authorInfo.name
      }}</a>
      <div class="resource-content">
        <div class="resource">
          <p class="resource-article">文章:{{ authorInfo.articles_count }}</p>
          <el-divider
            style="margin:0px 10px;"
            direction="vertical"
          ></el-divider>
        </div>
        <div class="resource">
          <p class="resource-video">视频:{{ authorInfo.videos_count }}</p>
          <el-divider style="margin:0px 7px;" direction="vertical"></el-divider>
        </div>
        <div class="resource">
          <p class="resource-document">文档:{{ authorInfo.documents_count }}</p>
          <el-divider style="margin:0px 7px;" direction="vertical"></el-divider>
        </div>
      </div>
    </div>
    <div class="articleContent">
      <div class="article" v-for="a in articleList" :key="a.id">
        <el-link
          class="title"
          type="info"
          @click="ToViewAuthorArticle(a)"
          :underline="false"
          >{{ a.article_title }}</el-link
        >
        <i class="view">阅读量:{{ a.like_count }}</i>
      </div>
    </div>
  </el-card>
</template>

<script>
export default {
  props: {
    article: {
      type: Object,
      required: false
    },
    musicScore: {
      type: Object,
      required: false
    }
  },
  components: {},
  data() {
    return {
      authorInfo: {},
      limit: 5,
      page: 1,
      articleList: []
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.getAuthorInfo()
    })
  },
  methods: {
    // 获取作者信息
    async getAuthorInfo() {
      const { article, musicScore } = this
      // 根据获得的参数查询作者
      let res
      if (article) {
        res = await this.$API.article.getAuthorByArticleId(this.article.info.id)
      } else if (musicScore) {
        res = await this.$API.musicScore.getAuthorByMusicScoreId(
          this.musicScore.info.id
        )
      }
      if (res.status == 200) {
        this.authorInfo = res.data
        // 获取文章列表
        this.getArticleList()
      }
    },
    // 获取文章信息
    async getArticleList() {
      const { authorInfo, limit, page } = this
      const res = await this.$API.article.getArticleByAuthorId(
        authorInfo.id,
        limit,
        page
      )
      if (res.status == 200) {
        this.articleList = res.data.payload
      }
    },
    // 跳转至作者推荐作品
    ToViewAuthorArticle(article) {
      this.$router.replace({
        name: 'ArticleDetail',
        params: { id: article.id }
      })
      window.location.reload()
    },
    // 跳转到作者主页
    GoAuthorPage() {
      this.$router.push('/homePage/' + this.authorInfo.id)
    }
  }
}
</script>

<style scoped>
.AuthorCard-content {
  width: 100%;
}
.header {
  display: flex;
  flex-wrap: wrap;
}
.author {
  width: 100%;
  margin-bottom: 10px;
  color: #121212;
  display: block;
  font-size: 16px;

  cursor: pointer;
  justify-content: space-between;
  text-align: center;
}
.author:hover {
  color: #aea9ad;
}
.resource-content {
  width: 100%;
  display: flex;
  justify-content: center;
}
.resource {
  height: 1em;
  display: flex;
  line-height: 1em;
  font-size: 12px;
}
.resource-article {
  color: #657274;
}
.resource-video {
  color: #657274;
}
.resource-document {
  color: #657274;
}
.articleContent {
  width: 100%;
}
.article {
  line-height: 2em;
  width: 100%;
}
.article .title {
  display: inline-block;
  font-size: 1em;
  font-weight: bold;
  width: 100%;
  color: #121212;
  margin-bottom: 0.2em;
  line-height: 1em;
}
.article .title:hover {
  color: #aea9ad;
}
.view {
  display: inline-block;
  font-size: 12px;
  color: #657274;
  width: 100%;
  line-height: 1em;
  height: 1em;
  margin-bottom: 20px;
}
</style>
